Skip to content

[feat] canvas: copy a selected image or text node to the system clipboard - #547

Closed
Labu1 wants to merge 2 commits into
ThinkFlowLab:mainfrom
Labu1:repodestek/issue-474
Closed

Labu1 wants to merge 2 commits into
ThinkFlowLab:mainfrom
Labu1:repodestek/issue-474

Conversation

@Labu1

@Labu1 Labu1 commented Nov 27, 2026 •

Copy link
Copy Markdown

Summary

  • Pressing Ctrl/Cmd+C on a single selected text node now also writes its plain text to the system clipboard. Unicode and line breaks are kept.
  • Pressing Ctrl/Cmd+C on a single selected image node now also writes PNG image data to the system clipboard, so the image can be pasted into email drafts, chat composers and slide editors. Other image formats are converted to PNG, because browsers only accept PNG clipboard images. The bytes come from the read the in-app copy already makes through the project asset client.
  • The success message appears only after the system clipboard accepts the write. If the media is missing, the browser cannot write images, or the write is rejected, a message in en-US and zh-CN says the copy only works on the canvas and suggests downloading the asset instead.
  • In-app copy and paste is unchanged. The keydown handler still handles Ctrl/Cmd+V on the canvas when an in-app fragment exists, so pasting does not also import the same image a second time. Multi-node selections and other node types stay in-app only.
  • Desktop: the owned Electron session denied every permission request, which also blocked clipboard writes. It now grants clipboard-sanitized-write only. Clipboard reads and all other permissions stay denied.

Scope note: this covers the main scenario in the issue, copying an image or text node out to other apps. It does not cover copying video to the clipboard with a download fallback, keeping nodes editable when copying between Web and desktop clients, or the manual checks across operating systems. Those remain follow-up work, and maintainers may prefer to treat this PR as Refs #474.

Linked issue

Refs #474

  • Fixes #N or Refs #N is included, or no issue applies

Labels

Suggested: type:feat, area:canvas, area:desktop.

  • Labels applied

Test plan

  • Local: Ran npm test in a clean Linux container: passed.
  • Left to CI: release checks. Manual paste into external apps (email, chat, slide editors) on macOS and Windows, in Web and desktop, has not been done.

New unit tests in tests/systemClipboard.test.ts use a stand-in clipboard. They cover Chinese and English text with line breaks, the PNG image write, multi-node and empty selections staying in-app, and localized errors for missing media, a rejected write and missing ClipboardItem support.

Evidence that it works

  • Media attached, or N/A because: not yet captured; manual verification in a browser and the desktop build is still needed.

Provider verification

  • Real-provider calls are described honestly, or none were made

Bilingual UI

  • Both locales are updated, or no user-facing copy changed

This PR was prepared with AI assistance (Claude) and reviewed by me before submitting.

…oard

Ctrl/Cmd+C on the canvas only filled the in-app clipboard, so a copied
image node could not be pasted into an email draft, chat composer or
slide editor. When exactly one text or image node is copied, also write
its plain text or PNG image data to the system clipboard, reusing the
bytes the in-app copy already captures. The write starts inside the
shortcut's user activation and success is reported only after the
platform accepts it; missing media, unsupported browsers and rejected
writes show bilingual messages that keep the in-app copy and suggest
downloading instead. In-app paste is unchanged.

The desktop session denied every permission, which also blocked
clipboard writes; it now grants clipboard-sanitized-write only.

Fixes ThinkFlowLab#474.
@github-actions github-actions Bot added area:canvas Canvas, nodes and direct manipulation area:desktop Desktop integration / 桌面集成 type:feat New capability or behaviour labels Nov 27, 2026

@wangtiance wangtiance left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这份 PR 把画布内的节点复制和系统剪贴板写入分开,保留了内部粘贴行为。我审了 0035b51 的代码和测试,有两处建议在交付前处理。

  1. 把桌面剪贴板授权限制在应用页面。 apps/desktop/src/main.mjs 目前只按权限名称放行,没有校验请求来源,也没有设置对应的 permission check handler。建议和 #458 共用同一套按来源校验的策略,确保只为 opendirector://app 授予所需的写入能力。请在实际 Electron 安装包中按 Ctrl/Cmd+C 分别复制文本和图片,再粘贴到外部应用。当前的 mock 测试覆盖了写入参数,但没有验证键盘手势和 Electron 权限回调是否能走通。

  2. 给缺失图片显示明确的回退提示。 systemClipboardPayload 在检查 assetState === "missing" 前就因为 src 为空返回 null,随后只显示普通的“已复制”提示。当前测试给缺失节点填了 blob:gone,没有覆盖无 src 的情况。建议先处理缺失状态,让这条路径明确提示只能在画布内粘贴,并补一个对应的测试。

建议把描述里的 Fixes #474 改成 Refs #474,让视频回退、双向粘贴和跨客户端可编辑内容继续留在原 issue 跟踪。当前提交的检查接口只返回了 reviewer routing 成功。我没有看到 Windows/macOS 安装包或 Web 与外部应用互贴的验收结果。

Grant clipboard-sanitized-write only to opendirector://app in both the
Electron permission request and check handlers, and give missing image
nodes without a src the in-app-only copy notice.
@Labu1

Labu1 commented Nov 29, 2026

Copy link
Copy Markdown
Author

@wangtiance 感谢审阅,两处都已处理:

  1. 桌面剪贴板授权按来源校验:在 apps/desktop/src/host.mjs 新增 grantsPermission(permission, origin)。它复用现有的 ownedURL,只为 opendirector://app 授予 clipboard-sanitized-write,读取剪贴板、其他权限以及其他来源一律拒绝。apps/desktop/src/main.mjs 的 setPermissionRequestHandler(按 details.requestingUrl 判断)和新增的 setPermissionCheckHandler(按 requestingOrigin 判断)都改为调用它。apps/desktop/tests/host.test.mjs 补充了来源和权限名称的正反用例。当前分支里没有找到 [bugfix] desktop: grant the renderer permissions the shell controls use #458 的共享实现,所以先基于 ownedURL 实现;如果 [bugfix] desktop: grant the renderer permissions the shell controls use #458 有统一策略,可以在合并时并入。

  2. 缺失图片的回退提示:systemClipboardPayload 现在先判断 assetState === "missing",再检查 src,所以没有 src 的缺失节点也会显示“已复制,仅可粘贴到画布”和原因。tests/systemClipboard.test.ts 新增了 src 为空的缺失节点用例。

验证:Ran npm test in a clean Linux container: passed.

我已把 PR 描述中的 Fixes #474 改为 Refs #474。目前还没有在真实的 Electron 安装包(Windows/macOS)里手动验证 Ctrl/Cmd+C 复制文本和图片节点再粘贴到外部应用,Web 端与外部应用之间的互贴也没有验证;合并前可能需要在打包版本里确认一下。

@wangtiance wangtiance left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复核了 2338e58。上轮两条代码意见都已处理。Electron 的请求和检查回调现在共用来源校验,只有应用自身的来源可写入剪贴板。缺失图片即使没有 src 也会走画布内复制的提示,并补了对应测试。Refs #474 也让剩余场景可以继续在原 issue 跟踪。

当前提交的 Release checks 和 Desktop checks 都显示 action_required,尚未看到通过结果。请有权限的维护者查看 Actions 页面上的处理提示。真实 Windows/macOS 安装包里用 Ctrl/Cmd+C 复制文本和图片,再粘贴到外部应用的验证也仍待完成。本次复核依据代码和远程检查状态。

@Labu1 Labu1 closed this Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:canvas Canvas, nodes and direct manipulation area:desktop Desktop integration / 桌面集成 type:feat New capability or behaviour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants